//我的企业
function enterpriseCenter() {
    new Vue({
        el: '#enterPrise',
        data() {
            return {
                Enterprise: ['企业信息', '营业执照信息', '组织机构代码证', '税务登记证', '开户银行许可证'],
                nowIndex: 0
            }
        },
        methods: {
            toggleTabs: function(index) {
                this.nowIndex = index;
            },
        },
        created: function() {

        }
    })
}

//我的品牌
function brandCenter() {
    new Vue({
        el: '#brand_list',
        data() {
            return {
                brandParam: ['品牌管理', '申请品牌入驻'],
                nowIndex: 0,
                logoUrl: {
                    base64: [""], // base64码
                    url: [""], //最后ajax提交表单信息时，提交的url路径，这个是单张图片上传完毕后台返回的url路径
                },
                picList: {
                    base64: [""], // base64码
                    url: [""], //最后ajax提交表单信息时，提交的url路径，这个是单张图片上传完毕后台返回的url路径
                },
                brandForm: {},
                labelData: {},
                brandForm_rules: {
                    companyName: [
                        { required: true, message: '请输入企业名称', trigger: 'blur' },
                    ],
                    brandName: [
                        { required: true, message: '请选择品牌名称', trigger: 'blur' },
                    ],
                    /*logoUrl:[
                        { required: true, message: '请上传品牌logo', trigger: 'change' }
                    ],*/
                    foundingTime: [
                        { required: true, message: '请选择成立时间', trigger: 'blur' }
                    ],
                    linkMan: [
                        { required: true, message: '请选择联系人', trigger: 'blur' }
                    ],
                    mobile: [
                        { required: true, message: '请选择联系方式', trigger: 'blur' }
                    ],
                },
                brandTable: [],
                pageNo: 1,
                pageSize: 10,
                total: 1,
                serverUrl: '',
                searchContent: '',
                status: '',
                fileUrl: urlParam.domain() + '/api/fileupload/upload?token=' + urlParam.token(),
                labelArray: []
            }
        },
        methods: {
            toggleTabs: function(index) {
                this.nowIndex = index;
            },
            listen: function(data) {
                this.pageNo = data;
                this.getBrandList();
            },
            toggleSelection(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            },

            //品牌管理
            getBrandList: function() {
                if (urlParam.token() == undefined || urlParam.token() == '') {
                    this.$message({
                        message: '请先登录',
                        type: 'warning'
                    });
                    return;
                }
                var that = this;
                axios.get(urlParam.domain() + '/api/brand/brand/brandList', {
                    params: {
                        pageNo: that.pageNo,
                        pageSize: that.pageSize,
                        token: urlParam.token(),
                        brandName: that.searchContent,
                        status: that.status
                    }
                }).then(function(response) {
                    if (response.data.code == 1) {
                        that.brandTable = response.data.data.list;
                        console.log(that.brandTable);
                        that.total = Math.ceil(response.data.data.total / that.pageSize);
                    }
                });
            },
            //获取品牌风格
            getLabelList() {
                var that = this;
                axios.get(urlParam.domain() + '/api/brand/label/getLabelList', {
                    params: {}
                }).then(function(response) {
                    if (response.data.data != undefined) {
                        that.labelData = response.data.data;
                        console.log(that.labelData);
                    }
                });
            },
            add: function(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.brandForm.logo = this.logoUrl.url[0];
                        this.brandForm.picList = [];
                        for (let url of this.picList.url) {
                            var obj = {};
                            obj.fileUrl = url;
                            this.brandForm.picList.push(obj);
                        }
                        this.brandForm.labels = [];
                        for (let labelId of this.labelArray) {
                            var obj = {};
                            obj.labelId = labelId;
                            this.brandForm.labels.push(obj);
                        }
                        this.brandForm.foundingTime = formatNormal(this.brandForm.foundingTime, 0);
                        let that = this;
                        axios.post(
                            urlParam.domain() + '/api/brand/brand/add',
                            JSON.stringify(that.brandForm), { headers: { "token": urlParam.token(), "Content-Type": "application/json" } }
                        ).then(result => {
                            console.log(result);
                            if (result.data.code == 1) {
                                that.brandForm = {};
                                that.nowIndex = 0;
                            }
                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });

            }
        },
        created: function() {
            this.getBrandList();
            this.getLabelList();
        }
    })
}

function formartPostParms(data) {
    var d = '';
    if (data instanceof Object) {
        for (var x in data) {
            if (data[x] === '') {
                continue;
            }
            d += '&' + x + '=' + data[x];
        }
    }
    return d.substr(1);
}

//店铺商品分类
function goodsTypeCenter() {
    new Vue({
        el: '#goodsType_list',
        data() {
            return {
                tabsParam: ['商品分类列表', '添加分类'],
                nowIndex: 0,
                input: "",
                value1: '',
                value2: '',
                ruleForm: {
                    input: '',
                    select: '',
                    text: ''
                },
                rules: {
                    name: [
                        { required: true, message: '请输入商品分类名称', trigger: 'blur' },
                    ],
                    region: [
                        { required: true, message: '请选择上一级分类', trigger: 'change' }
                    ]
                },
                tableData: [
                    { id: '3', type: '0001', name: '女装', prev: '休闲装', title: '无', date: '2017-12-12 12:09:09' },
                    { id: '3', type: '0001', name: '女装', prev: '休闲装', title: '无', date: '2017-12-12 12:09:09' },
                    { id: '3', type: '0001', name: '女装', prev: '休闲装', title: '无', date: '2017-12-12 12:09:09' },
                    { id: '3', type: '0001', name: '女装', prev: '休闲装', title: '无', date: '2017-12-12 12:09:09' },
                    { id: '3', type: '0001', name: '女装', prev: '休闲装', title: '无', date: '2017-12-12 12:09:09' },
                    { id: '3', type: '0001', name: '女装', prev: '休闲装', title: '无', date: '2017-12-12 12:09:09' },
                    { id: '3', type: '0001', name: '女装', prev: '休闲装', title: '无', date: '2017-12-12 12:09:09' },
                    { id: '3', type: '0001', name: '女装', prev: '休闲装', title: '无', date: '2017-12-12 12:09:09' },
                ],
                pageNo: 1,
                pageSize: 10,
                total: 1,
                serverUrl: '',
                searchContent: '',
                pageNo: 1,
                pageSize: 10,
                total: 1,
                serverUrl: '',
                searchContent: '',
                options: []
            }
        },
        methods: {
            getData() {
                var that = this;
                console.log(urlParam.token())
                axios.get(urlParam.domain() + '/api/shop/goodsCompanyCategory/toAdd', {
                    params: {
                        token: urlParam.token()
                    }
                }).then(function(response) {
                    console.log(response.data.data);
                    var a = response.data.data
                    var b = {
                        name: "无",
                        id: 0
                    }
                    a.unshift(b)
                        /*  console.log(a)*/
                    that.options = a;
                });
            },
            setGoodsType() {
                console.log(1111)
                var that = this;
                console.log("---------" + urlParam.token());
                axios({
                    method: "post",
                    url: urlParam.domain() + '/api/shop/goodsCompanyCategory/add',
                    data: {
                        token: urlParam.token(),
                        name: that.ruleForm.input,
                        parentId: that.ruleForm.select,
                        remarks: that.ruleForm.text
                    },
                    transformRequest: [function(data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(function(response) {
                    /*console.log(response.data.data);
                    that.options = response.data.data;*/
                    that.$message({
                        message: '新增成功',
                        type: 'success'
                    });
                    that.ruleForm.text = '';
                    that.ruleForm.select = '';
                    that.ruleForm.input = '';
                    that.getData();
                });
            },
            toggleTabs: function(index) {
                this.nowIndex = index;
            },
            listen: function(data) {
                this.pageNo = data;
                this.changeData();
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            }
        },
        created: function() {
            this.getData();
            var myDate = new Date();
            var today = myDate.toLocaleDateString();
            this.value1 = today;
            this.value2 = today;
        }
    })
}


// 发布商品 
function add_Goods() {
    add_Goods = new Vue({
        el: '#add_Goods',
        data() {
            return {
                active: 0, //第一步
                name: "",
                checked: '',
                value: '',
                imageUrl: '',
                radio: '1', //是否开增值税发票
                radio1: '1', //上架时间
                checkList: [], //商品基础保障
                value1: '2018-02-08 12:09:59', //上架时间
                steps_items: [
                    { id: '1', title: '选择商品类目' },
                    { id: '2', title: '填写商品信息' },
                    { id: '3', title: '上传商品图片' },
                ],
                ruleForm: {
                    //name: '',
                    num: '',
                    region1: '', //选择店铺商品分类 第一个选项 选中项下标
                    region2: '', //选择店铺商品分类 第二个选项 选中项下标
                    date1: '',
                    date2: '',
                    delivery: false,
                    type: [],
                    resource: '',
                    desc: '',
                    goodsAttributeAndValueList: []
                },
                /*
                rules: {
                    name: [
                        { required: true, message: '请输入活动名称', trigger: 'blur' },
                        { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                    ],
                    region2: [
                        { required: true, message: '请选择店铺商品分类', trigger: 'change' }
                    ],
                    date1: [
                        { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
                    ],
                    date2: [
                        { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
                    ],
                    type: [
                        { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
                    ],
                    resource: [
                        { required: true, message: '请选择活动资源', trigger: 'change' }
                    ],
                    desc: [
                        { required: true, message: '请填写活动形式', trigger: 'blur' }
                    ]
                },
                */
                preimg: {
                    base64: [""], //这个 preimg.base64 才是 预览图
                    url: [""], //最后ajax提交表单信息时，提交的url路径，这个是单张图片上传完毕后台返回的url路径
                },
                //第一步 *********************************************
                //商品类目 选项
                options1: [],
                options2: [],
                options3: [],
                options1Index: "", //选择商品类目 第一个选项 选中项下标
                options2Index: "", //选择商品类目 第二个选项 选中项下标
                options3Index: "", //选择商品类目 第三个选项 选中项下标
                // end of 第一步
                //第二步 *********************************************
                options4: [], //店铺中分类 第一个选项
                options5: [], //店铺中分类 第二个选项
                goodsProperty: [], //商品属性 选项下标 数组 通过这个生成 ajaxUpData.goodsAttributeAndValueList 商品属性
                majorInformation: { //商品属性 选项 通过第一步 ajax获取
                    goodsGroupList: [{ //商品属性 不包括品牌
                        specName: "", //选项类别 名称
                        id: "", //选项类别 id
                        goodsAttributeValueList: [{ //选项
                            valueName: "", //选项 名称
                            id: "", //id
                        }]
                    }],
                    color: { //商品规格 颜色
                        goodsSpecValueList: [{
                            specValue: "", //文字
                            id: "", //id
                        }]
                    },
                    size: { //商品规格 尺码
                        goodsSpecValueList: [{
                            specValue: "", //文字
                            id: "", //id
                        }]
                    }
                },
                colorRadio: 0, //选中的颜色
                sizeList: [], //尺码 二维数组 下标（数字）集合
                amountList: [], //库存 二维数组 与上面的尺码对应
                goodsTotalNum: 0, //库存 总量

                // end of 第二步
                ajaxUpData: { //最后提交的json格式
                    //第一步 *************************
                    "oneCategoryId": "", //商品类目 选项1
                    "twoCategoryId": "", //商品类目 选项2
                    "categoryId": "", //商品类目 选项3
                    //第二步 **************************
                    "goodsName": "", //商品名称
                    "goodsNumber": "", //商品编号
                    "categoryId": "", //店铺中分类 第二个选项的id
                    "introduce": "", //商品卖点
                    "brandId": "", //品牌id
                    "goodsAttributeAndValueList": [{ //商品属性
                        "attributeId": "", //选项类别
                        "attributeValueId": "" //选项id
                    }],
                    "goodsPrice": "", //基本价格
                    "goodsSkuStockList": [{ //商品销售规格
                        "colorId": "",
                        "sizeId": "",
                        "basicPrice": "", //基本价格
                        "amount": "", //库存
                    }],
                    "goodsBteList": [{ //销售商品价格区间
                        "unitPrice": "", //价格 越来越低
                        "minNum": "", //
                        "maxNum": null, //数组最后一个对象 这个是null
                    }],
                    "describe": "", //商品描述
                    "ifInvoice": 0, //商品发布信息 是否开增值税发票 0 否 1 是
                    "basicGuarantee": [], //商品基础保障 012 上传时需先排序再变为字符串
                },

                changeViewData: { //用于更新视图的数据
                    data: 0
                }
            }
        },
        methods: {
            getData() {
                var that = this;

                //第一步 的 商品类目 选项
                axios.get(urlParam.domain() + '/api/shop/goods/listGoodsCategory', {
                    params: {}
                }).then(function(response) {
                    that.options1 = response.data.data;
                });
                //第二部 的 店铺中分类 选项
                axios({
                    method: "get",
                    url: urlParam.domain() + "/api/shop/goodsCompanyCategory/list",
                    params: {},
                    headers: { "token": urlParam.token() }
                }).then(function(res) {
                    // console.log(res.data.data)
                    that.options4 = res.data.data;
                });

            },
            //数据变化后 更新视图
            changeView() {
                this.$set(this.changeViewData, "data", ++this.changeViewData.data);
            },
            //第一步 *********************************************************************
            //选择商品类目 选择第一个选项
            chooseOptions1(index) {
                this.options2 = this.options1[index].childCategoryList; //生成第二个选项列表
                this.options3 = []; //清空第三个选项列表
                this.options2Index = ""; //清空第二个选中项
                this.options3Index = ""; //清空第三个选中项
            },
            //选择商品类目 选择第二个选项
            chooseOptions2(index) {
                this.options3 = this.options2[index].childCategoryList; //生成第三个选项列表
                this.options3Index = ""; //清空第三个选中项
            },
            //点击 第一步 的 下一步 获取商品基本信息
            getMajorInformation(categoryId) {
                var that = this;
                axios({
                    method: "post",
                    url: urlParam.domain() + '/api/shop/goods/toAddProduct',
                    data: {
                        token: urlParam.token(),
                        categoryId: categoryId
                    },
                    transformRequest: [function(data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(function(response) {
                    //
                    for (var i = 0; i < response.data.data.color.goodsSpecValueList.length; i++) {
                        that.sizeList[i] = []; //生成 尺码 element ui 绑定的二维数组
                        that.amountList[i] = []; //生成 尺码对应的库存
                    }
                    that.majorInformation = response.data.data;
                    // console.log(that.majorInformation);
                });
            },
            //第一步 end ***************************************************************************
            //第二步 ********************************************************************
            //选择 店铺中分类 选择第二个选项
            chooseOptions4(index) {
                this.options5 = this.options4[index].children; //生成下一个选项列表
                this.ruleForm.region2 = ''; //清空下一个选中项
            },
            //选择尺码 计算库存总数
            chooseSize() {
                this.calTotal();
            },
            //验证 基础价格
            blurInputPrice() {
                var num = this.ajaxUpData.goodsPrice;
                if (!(num - 0)) { //验证是否为数字
                    num = 0;
                } else if (num < 0) { //验证 不能是小于0的数
                    num = 0;
                } else { //取整数
                    num = parseInt(num);
                }
                this.ajaxUpData.goodsPrice = num.toFixed(2);
            },
            //商品销售规格 失去焦点 验证 计算总数
            blurInput(obj, index, subindex) {
                var num = obj[index][subindex];
                if (!(num - 0)) { //验证是否为数字
                    num = 0;
                } else if (num < 0) { //验证 不能是小于0的数
                    num = 0;
                } else { //取整数
                    num = parseInt(num);
                }
                obj[index][subindex] = num;
                this.calTotal();
                this.changeView();
            },
            //计算 库存 总量
            calTotal() {
                var num = 0;
                for (var i = 0; i < this.sizeList.length; i++) {
                    for (var j = 0; j < this.sizeList[i].length; j++) {
                        if (this.amountList[i][this.sizeList[i][j]]) { //价格初始值为空 所以判断一下
                            num = num + this.amountList[i][this.sizeList[i][j]];
                        }
                    }
                }
                this.goodsTotalNum = num; //总量
            },
            //点击 添加 销售商品价格区间
            addGoodsBteList() {
                if (this.ajaxUpData.goodsBteList.length < 3) {
                    this.ajaxUpData.goodsBteList.push({
                        "unitPrice": "",
                        "minNum": "",
                        "maxNum": null,
                    });
                } else {
                    this.$message({ message: '最多3个价格区间', type: 'warning' });
                }
            },
            //点击 删除 销售商品价格区间
            delGoodsBteList(index) {
                this.ajaxUpData.goodsBteList.splice(index, 1);
            },
            //第二步 end *************************************************************************
            //点击下一步
            next() {
                switch (this.active) {
                    case 0: //第一步
                        if (this.options3Index === "") { //未选择 商品类目
                            this.$message({ message: '请选择商品类目', type: 'warning' });
                            return;
                        } else {
                            this.getMajorInformation(this.options3[this.options3Index].id);
                        }
                        this.active++;
                        break;
                    case 1: //第二步
                        //验证必选项
                        if (!this.ajaxUpData.goodsName) { //商品名称
                            this.$message({ message: '请填写商品名称', type: 'warning' });
                            return;
                        }
                        if (!this.ajaxUpData.goodsNumber) { //商品编号
                            this.$message({ message: '请填写商品编号', type: 'warning' });
                            return;
                        }
                        if (this.ajaxUpData.categoryId == "") { //店铺中分类
                            this.$message({ message: '请选择店铺中分类', type: 'warning' });
                            return;
                        }
                        if (!this.ajaxUpData.introduce) { //商品卖点
                            this.$message({ message: '请填写商品卖点', type: 'warning' });
                            return;
                        }
                        if (this.ajaxUpData.brandId == "") { //商品属性 品牌
                            this.$message({ message: '请选择商品属性 品牌', type: 'warning' });
                            return;
                        }
                        //商品属性 品牌之外的选项
                        if (this.goodsProperty.length == this.majorInformation.goodsGroupList.length) { //如果最后一个选项有值，继续判断
                            for (var i = 0; i < this.goodsProperty.length; i++) {
                                if (this.goodsProperty[i] == undefined) {
                                    this.$message({ message: '请选择商品属性', type: 'warning' });
                                    return;
                                }
                            }
                            // console.log("商品属性 验证通过");
                        } else {
                            this.$message({ message: '请选择商品属性', type: 'warning' });
                            return;
                        }
                        //基础价
                        if (!this.ajaxUpData.goodsPrice) {
                            this.$message({ message: '请填写基础价格', type: 'warning' });
                            return;
                        }
                        //库存 二维数组 不能有0 注意，可能为空  用尺码 sizeList 去取库存 amountList
                        for (var i = 0; i < this.sizeList.length; i++) {
                            for (var j = 0; j < this.sizeList[i].length; j++) {
                                if (!this.amountList[i][this.sizeList[i][j]]) { //如果 为0 或者 为空
                                    this.$message({ message: '库存不能为0，如果没有该尺码，请取消选择', type: 'warning' });
                                    return;
                                }
                            }
                        }
                        //库存 总量 不能为0
                        if (this.goodsTotalNum == 0) {
                            this.$message({ message: '亲，现在没有货物哦', type: 'warning' });
                            return;
                        }
                        //销售商品价格区间 this.ajaxUpData.goodsBteList
                        for (var i = 0; i < this.ajaxUpData.goodsBteList.length; i++) {
                            if (!this.ajaxUpData.goodsBteList[i].unitPrice || !this.ajaxUpData.goodsBteList[i].minNum) {
                                this.$message({ message: '请完善销售商品价格区间', type: 'warning' });
                                return;
                            }
                            if (i == 0 && ((this.ajaxUpData.goodsBteList[0].unitPrice - 0) > (this.ajaxUpData.goodsPrice - 0))) { //如果 起批量价格 大于 基础价格
                                this.$message({ message: '价格区间起始价格不能大于基础价格，亲，不能买的越多卖的越贵啊', type: 'warning' });
                                return;
                            } else if (
                                i > 0 && (
                                    ((this.ajaxUpData.goodsBteList[i].unitPrice - 0) >= (this.ajaxUpData.goodsBteList[i - 1].unitPrice - 0)) || //价格越低
                                    ((this.ajaxUpData.goodsBteList[i].minNum - 0) <= (this.ajaxUpData.goodsBteList[i - 1].minNum - 0)) //起批量越大
                                )
                            ) {
                                this.$message({ message: '价格区间填写错误，亲，应该是卖的越多越便宜', type: 'warning' });
                                return;
                            }
                        }

                        //验证通过 
                        //生成 ajaxUpData.goodsAttributeAndValueList 商品属性 选项
                        for (var i = 0; i < this.goodsProperty.length; i++) {
                            this.ajaxUpData.goodsAttributeAndValueList[i]
                        }
                        this.active++;
                        break;
                }
            },
            //点击上一步
            prev() {
                this.active--;
            },
        },
        created() {
            this.getData();

        },
        updated() {
            // console.log(this.ruleForm.goodsAttributeAndValueList)
        }
    })
}

function goods() {
    new Vue({
        el: '#goods',
        data() {
            return {
                goodsParam: ['待上架商品', '出售中商品', '已下架商品'],
                nowIndex: 0,
                input: "",
                value: '',
                options: [{}],
                value1: '',
                value2: '',
                ruleForm: {
                    input: '',
                    select: '',
                    text: ''
                },
                rules: {
                    name: [
                        { required: true, message: '请输入商品分类名称', trigger: 'blur' },
                    ],
                    region: [
                        { required: true, message: '请选择上一级分类', trigger: 'change' },
                    ],
                    value: [
                        { required: true, message: '请选择上一级分类', trigger: 'change' },
                    ]
                },
                tableData: [],
                pageNo: 1,
                total: '',
                serverUrl: '',
                searchContent: '',
                options1: [],
                options2: [],
                options1Index: "", //选择店铺商品分类 第一个选项 选中项下标
                options2Index: "", //选择店铺商品分类 第二个选项 选中项下标
                goodsCompanyCategoryId:null
            }
        },
        methods: {
            getData(){
                var that = this;

                // console.log(that.options2Index);
                // console.log(that.options2[that.options2Index]);
                if(that.options2Index.length != 0){
                    that.goodsCompanyCategoryId = that.options2[that.options2Index].id;
                    // console.log(that.goodsCompanyCategoryId);
                }

                // console.log((that.value1).toLocaleDateString());
                // console.log((that.value2).toLocaleDateString());
                console.log("---------"+that.nowIndex);

                if(that.value1.length !=0 && that.value2.length !=0){
                    that.value1 = (that.value1).toLocaleDateString();
                    that.value2 = (that.value2).toLocaleDateString();
                    console.log(that.value1);
                    console.log(that.value2);
                }

                //店铺中分类 选项
                axios({
                    method: "get",
                    url: urlParam.domain() + "/api/shop/goodsCompanyCategory/list",
                    params: {},
                    headers: { "token": urlParam.token() }
                }).then(function(res) {
                    // console.log(res.data.data)
                    that.options1 = res.data.data;
                });


                axios.get(urlParam.domain() + '/api/shop/goods/selectNewList/', {
                    params: {
                        pageNo: that.pageNo,
                        pageSize: 5,
                        token: urlParam.token(),
                        status: that.nowIndex,
                        goodsName:that.ruleForm.input,
                        goodsCompanyCategoryId:that.goodsCompanyCategoryId,
                        startTime: that.value1,
                        endTime: that.value2
                    }
                }).then(function(response) {
                    console.log(response.data.data);
                    that.tableData = response.data.data.list;
                    that.total = getPageCount(response.data.data.total, 5);
                });


            },
            //选择 店铺中分类 选择第二个选项
            chooseOptions1(index) {
                this.options2 = this.options1[index].children; //生成下一个选项列表
                this.options2Index = ''; //清空下一个选中项
            },
            toggleTabs: function(index) {
                this.nowIndex = index;
                console.log(this.nowIndex);
                this.getData();
            },
            aa(){
                console.log(1111);
                console.log(this.ruleForm.input);
                // console.log(this.options2[this.options2Index].id);
                this.getData();

                this.ruleForm.input=null;
                this.options1Index='';
                this.options2Index='';
                this.goodsCompanyCategoryId=null;
                this.value1='';
                this.value2='';
            },
            // listen: function(data) {
            //     this.pageNo = data;
            // },
            getPage(page) {
                this.pageNo = page;

                this.getData();
            },
        },
        created: function() {
            var myDate = new Date();
            var today = myDate.toLocaleDateString();
            // this.value1 = today;
            // this.value2 = today;
            this.getData();
        }
    })
}

//系统通知

function system() {
    new Vue({
        el: '#system',
        data() {
            return {

            }
        },
        methods: {
            listen: function(data) {
                this.pageNo = data;
            },
        },
    })
}

//关注、收藏中心
function focusCenter() {
    new Vue({
        el: '#focus_list',
        data() {
            return {
                focus_tabs: ['收藏的商品', '关注的店铺', '关注的品牌', '关注的企业', '关注我的企业'],
                nowIndex: 0,
                input: "",
                value1: '',
                value2: '',
                focus_delete: -1,
                shop_delete: -1,
                goods: [],
                brands: [],
                companys: [],
                followCompanys: [],
                pageNo: 1,
                pageSize: 10,
                total: 1,
                serverUrl: '',
                searchContent: ''
            }
        },
        methods: {
            //控制页面跳转
            chang_hash: function(params) {
                let that = this;
                let hash_number = location.hash;
                that.nowIndex = Number(hash_number.slice(1, hash_number.length)) - 1;
            },
            hash_num: function() {
                let that = this;
                window.onhashchange = function() {
                    let hash_number = location.hash;
                    that.nowIndex = Number(hash_number.slice(1, hash_number.length)) - 1;
                }
            },

            toggleTabs: function(index) {
                if (this.nowIndex != index) {
                    this.pageNo = 1;
                    this.pageSize = 10;
                    this.searchContent = '';
                }
                this.nowIndex = index;
                this.changeData();
                window.location.hash = '#' + Number(this.nowIndex + 1); //控制页面跳转
            },
            listen: function(data) {
                this.pageNo = data;
                this.changeData();
            },
            toggleSelection(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            deleteGoods: function(index) {
                console.log(this.goods[index].bId + ",");
                var ids = this.goods[index].bId + ",";
                this.delCollectionGoods(ids);
                //表面删除
                // this.goods.splice(index, 1);
                this.focus_delete = -1;
            },
            showMask: function(index) {
                this.focus_delete = index;
            },
            hiddenMask: function(index) {
                this.focus_delete = -1;
            },
            show_shopMask: function(index) {
                this.shop_delete = index;
            },
            hidden_shopMask: function(index) {
                this.shop_delete = -1;
            },
            deleteShops: function(index) {
                this.focus_shop.splice(index, 1);
                this.shop_delete = -1;
            },
            //收藏的商品
            getGoods: function() {
                var that = this;
                axios.get(urlParam.domain() + '/api/shop/goods/myCollectGoods', {
                    params: {
                        pageNo: that.pageNo,
                        pageSize: that.pageSize,
                        token: urlParam.token(),
                        goodsName: that.searchContent
                    }
                }).then(function(response) {
                    if (response.data.code == 1) {
                        console.log(response.data.data.list)
                        that.goods = response.data.data.list;
                        that.total = Math.ceil(response.data.data.total / that.pageSize);
                        that.serverUrl = response.data.data.serverUrl;
                    }
                });
            },
            //取消收藏的商品
            delCollectionGoods: function(ids) {
                var that = this;
                axios.get(urlParam.domain() + '/api/shop/goodsCollecting/delete', {
                    params: {
                        ids: ids,
                        token: urlParam.token()
                    }
                }).then(function(response) {

                });
            },
            //关注的品牌
            getBrands: function() {
                var that = this;
                axios.get(urlParam.domain() + '/api/brand/brand/myList', {
                    params: {
                        pageNo: that.pageNo,
                        pageSize: that.pageSize,
                        token: urlParam.token(),
                        brandName: that.searchContent
                    }
                }).then(function(response) {
                    if (response.data.code == 1) {
                        that.brands = response.data.data.list;
                        console.log(that.brands);
                        that.total = Math.ceil(response.data.data.total / that.pageSize);
                    }
                });
            },
            //关注的企业
            getCompanys: function() {
                var that = this;
                axios.get(urlParam.domain() + '/api/company/company/myFollowCompanylist', {
                    params: {
                        pageNo: that.pageNo,
                        pageSize: that.pageSize,
                        token: urlParam.token(),
                        name: that.searchContent
                    }
                }).then(function(response) {
                    if (response.data.code == 1) {
                        that.companys = response.data.data.list;
                        console.log(that.companys);
                        that.total = Math.ceil(response.data.data.total / that.pageSize);
                        that.serverUrl = response.data.data.serverUrl;
                    }
                });
            },
            //关注我的企业
            getFollowCompanys: function() {
                var that = this;
                axios.get(urlParam.domain() + '/api/company/company/follwMyCompanylist', {
                    params: {
                        pageNo: that.pageNo,
                        pageSize: that.pageSize,
                        token: urlParam.token(),
                        name: that.searchContent
                    }
                }).then(function(response) {
                    if (response.data.code == 1) {
                        that.followCompanys = response.data.data.list;
                        console.log(that.followCompanys);
                        that.total = Math.ceil(response.data.data.total / that.pageSize);
                        that.serverUrl = response.data.data.serverUrl;
                    }
                });
            },
            //动态发请求或搜索
            changeData: function() {
                if (this.nowIndex == 0) {
                    this.getGoods();
                }
                if (this.nowIndex == 1) {

                }
                if (this.nowIndex == 2) {
                    this.getBrands();
                }
                if (this.nowIndex == 3) {
                    this.getCompanys();
                }
                if (this.nowIndex == 4) {
                    this.getFollowCompanys();
                }
            }
        },
        created: function() {
            var myDate = new Date();
            var today = myDate.toLocaleDateString();
            this.value1 = today;
            this.value2 = today;
            this.chang_hash();
            this.hash_num();
            //收藏的商品
            this.getGoods();
        }
    })
}

//品牌加盟
function brandJoinCenter() {
    new Vue({
        el: '#brand_join_list',
        data() {
            return {
                brandJoinParam: ['品牌加盟'],
                nowIndex: 0,
                pageNo: 1,
                pageSize: 10,
                total: 1,
                serverUrl: '',
                searchContent: '',
                brandJoinTable: {}
            }
        },
        methods: {
            toggleTabs: function(index) {
                this.nowIndex = index;
            },
            listen: function(data) {
                this.pageNo = data;
                this.brandJoinData();
            },
            brandJoinData: function() {
                let that = this;
                axios.get(urlParam.domain() + '/api/brand/leaqueApply/list', {
                    params: {
                        pageNo: that.pageNo,
                        pageSize: that.pageSize,
                        brandId: 1,
                        token: urlParam.token(),
                        contacts: that.searchContent
                    }
                }).then(function(response) {
                    if (response.data.code == 1) {
                        console.log(response.data.data);
                        that.brandJoinTable = response.data.data.list;
                        that.total = Math.ceil(response.data.data.total / that.pageSize);
                    }
                });
            }

        },
        created: function() {
            this.brandJoinData();
        }
    })
}

/* 品牌详情 */

function brand_details() {
    new Vue({
        el: '#brand_details',
        data() {
            return {
                brand_details: ['品牌详情'],
                nowIndex: 0,
                brand: {},
                attachments: []
            }
        },
        methods: {
            toggleTabs: function(index) {
                this.nowIndex = index;
            },
            getDate: function() {
                let id = window.location.href.split("?")[1];
                let that = this;
                axios.get(urlParam.domain() + '/api/brand/brand/detail?', {
                    params: {
                        id: id
                    }
                }).then(function(response) {
                    console.log(response.data.data);
                    that.brand = response.data.data.brand;
                    that.attachments = response.data.data.attachments;
                });
            },
            goList: function() {
                window.location = '../jusercenter/branding.html';
            }
        },
        created: function() {
            this.getDate();
        }
    })
}

function brand_info() {
    new Vue({
        el: '#brand_info',
        data() {
            return {
                nowIndex: 0,
                brand_info: ['品牌介绍'],

            }

        }
    })
}

/* 企业详情 */
function enterPrise_info(params) {
    new Vue({
        el: '#Enterprise_info',
        data() {
            return {
                imageUrl: '',
                nowIndex: 0,
                value1: '江苏省',
                value2: '南京市',
                value3: '六合区',
                Enterprise_infoParam: ['企业资料'],
                Enterprise_customer: ['企业客服'],
                EnterpriseForm: {
                    name: '',
                    region: '',
                    text: ''
                },
                EnterpriseForm_rules: {
                    name: [
                        { required: true, message: '请输入商品分类名称', trigger: 'blur' },
                    ],
                    region: [
                        { required: true, message: '请选择上一级分类', trigger: 'change' }
                    ]
                },
            }
        },
    })
}


//品牌加盟详情
function join_details() {
    new Vue({
        el: '#join_details',
        data() {
            return {
                join_details: ['加盟详情'],
                nowIndex: 0,
                joinDetailInfo: {}
            }
        },
        methods: {
            toggleTabs: function(index) {
                this.nowIndex = index;
            },
            getDate: function() {
                let id = window.location.href.split("?")[1];
                let that = this;
                axios.get(urlParam.domain() + '/api/brand/leaqueApply/details', {
                    params: {
                        id: id,
                        token: urlParam.token()
                    }
                }).then(function(response) {
                    if (response.data.code == 1) {
                        that.joinDetailInfo = response.data.data;
                    }
                    console.log(that.joinDetailInfo);
                });
            },
            toList: function() {
                window.location = '../jusercenter/brand_join.html';
            }
        },
        created: function() {
            this.getDate();
        }
    })
}

//我的订单-聚订单
function order_jdd() {
    new Vue({
        el: '#order_jdd',
        data() {
            return {
                nowIndex: 0,
                tabsParam: ['全部', '发布', '交易', '评价'],
                list: [{
                    createtime: '2017-12-09  12:09:09',
                    ordernum: '56564646464',
                    name: '面料采购：针织、平纹、复合',
                    param: '针织坑条，间距如图，克重240g以内',
                    baojia: '2个报价',
                    state: '报价中',
                }, {
                    createtime: '2017-12-09  12:09:09',
                    ordernum: '56564646464',
                    name: '面料采购：针织、平纹、复合',
                    param: '针织坑条，间距如图，克重240g以内',
                    baojia: '2个报价',
                    state: '报价中',
                }, {
                    createtime: '2017-12-09  12:09:09',
                    ordernum: '56564646464',
                    name: '面料采购：针织、平纹、复合',
                    param: '针织坑条，间距如图，克重240g以内',
                    baojia: '2个报价',
                    state: '报价中',
                }],
                total:0,
                pageNo:1,
                pageSize:3
            }
        },
        methods: {
            toggleTabs(i) {
                this.nowIndex = i;
                //重新筛选数据
            },
            getOrderList(){
                //卖家中心聚订单列表
                let that=this;
                axios.get(urlParam.domain()+'/api/order/order/list',{
                    params:{
                        pageNo:that.pageNo,
                        pageSize:that.pageSize,
                        service:0,
                        status:'',
                        token:urlParam.token()
                    }
                }).then(function (response) {
                    console.log(response.data.data);
                    that.list = response.data.data.list;
                    that.total = Math.ceil(response.data.data.total / that.pageSize);
                });
            },
            listen: function(data) {
                // 翻页事件
                this.pageNo = data;
                this.getOrderList();
            }
        },
        created() {
            this.getOrderList();
        }
    })
}

//我的订单-聚服务
function order_jfw() {
    new Vue({
        el: '#order_jfw',
        data() {
            return {
                nowIndex: 0,
                tabsParam: ['全部', '发布', '交易', '评价'],
                list: [{
                    createtime: '2017-12-09  12:09:09',
                    ordernum: '56564646464',
                    name: '面料采购：针织、平纹、复合',
                    param: '针织坑条，间距如图，克重240g以内',
                    baojia: '2个报价',
                    state: '报价中',
                }, {
                    createtime: '2017-12-09  12:09:09',
                    ordernum: '56564646464',
                    name: '面料采购：针织、平纹、复合',
                    param: '针织坑条，间距如图，克重240g以内',
                    baojia: '2个报价',
                    state: '报价中',
                }, {
                    createtime: '2017-12-09  12:09:09',
                    ordernum: '56564646464',
                    name: '面料采购：针织、平纹、复合',
                    param: '针织坑条，间距如图，克重240g以内',
                    baojia: '2个报价',
                    state: '报价中',
                }]
            }
        },
        methods: {
            toggleTabs(i) {
                this.nowIndex = i;
                //重新筛选数据
            }
        },
        created() {

        }
    })
}

//我的订单-聚订单-填写物流信息
function order_wuliu() {
    new Vue({
        el: '#order_wuliu',
        data() {
            return {
                ruleForm: {
                    name: '',
                    region: '',
                },
                rules: {
                    number: [
                        { required: true, message: '请输入物流单号', trigger: 'blur' },
                    ],
                    company: [
                        { required: true, message: '请选择物流公司', trigger: 'change' }
                    ]
                }
            }
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        alert('submit!');
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            }
        },
        created() {

        }
    })
}

//订单详情-聚订单
function order_detail_jdd() {
    new Vue({
        el: '#order_detail_jdd',
        data() {
            return {
                list: [{
                    createtime: '2017-12-09  12:09:09',
                    ordernum: '56564646464',
                    name: '针织面料',
                    price: '￥36/斤',
                    count: '2',
                }]
            }
        },
        methods: {
            getData() {

            }
        },
        created() {
            this.getData();
        }
    })
}

//订单评价-聚订单
function order_pingjia_jdd() {
    new Vue({
        el: '#order_pingjia_jdd',
        data() {
            return {
                list: [{
                    createtime: '2017-12-09  12:09:09',
                    ordernum: '56564646464',
                    name: '针织面料',
                    price: '￥36/斤',
                    count: '2',
                }],
                star: 0,
            }
        },
        methods: {
            getData() {

            },
            dafen(n) {
                this.star = n;
            }
        },
        created() {
            this.getData();
        }
    })
}

//订单详情-聚订单-买家
function order_detail_buyer() {
    new Vue({
        el: '#order_detail_buyer',
        data() {
            return {
                list: [{
                    createtime: '2017-12-09  12:09:09',
                    ordernum: '56564646464',
                    name: '针织面料',
                    price: '￥36/斤',
                    count: '2',
                }]
            }
        },
        methods: {
            getData() {

            }
        },
        created() {
            this.getData();
        }
    })
}

//买家中心-报价详情
function ucenter_baojia_detail() {
    new Vue({
        el: '#ucenter_baojia_detail',
        data() {
            return {

            }
        },
        methods: {

        },
        created() {

        }
    })
}

//品牌管理-品牌形象
function pinpai_xingx() {
    new Vue({
        el: '#pinpai_xingx',
        data() {
            return {
                nowIndex: 0,
                tabsParam: ['品牌形象', '添加品牌形象'],
                list: [{
                    name: 'EXCEPTION 2018年春季发布会秀场图片',
                    state: 1,
                    time: '2017-12-12'
                }, {
                    name: 'EXCEPTION 2018年春季发布会秀场图片',
                    state: 1,
                    time: '2017-12-12'
                }],
                ruleForm: {
                    name: '',
                    state: '1',
                    pics: {
                        base64: [""], //base64码 预览图
                        url: [""], //最后ajax提交表单信息时，提交的url路径，这个是单张图片上传完毕后台返回的url路径
                    }
                },
                rules: {
                    name: [
                        { required: true, message: '请输入标题', trigger: 'blur' },
                        { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                    ]
                }
            }
        },
        methods: {
            //tab切换
            toggleTabs(i) {
                this.nowIndex = i;
            },
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        alert('submit!');
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
        },
        created() {

        }
    })
}

//品牌管理-品牌动态
function pinpai_dongt() {
    new Vue({
        el: '#pinpai_dongt',
        data() {
            return {
                nowIndex: 0,
                tabsParam: ['品牌动态', '发布动态'],
                list: [{
                    name: 'EXCEPTION 2018年春季发布会秀场图片',
                    state: 1,
                    time: '2017-12-12'
                }, {
                    name: 'EXCEPTION 2018年春季发布会秀场图片',
                    state: 1,
                    time: '2017-12-12'
                }],
                ruleForm: {
                    name: '',
                    state: '1',
                    pics: {
                        base64: [""], //base64码 预览图
                        url: [""], //最后ajax提交表单信息时，提交的url路径，这个是单张图片上传完毕后台返回的url路径
                    }
                },
                rules: {
                    name: [
                        { required: true, message: '请输入标题', trigger: 'blur' },
                        { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                    ]
                }
            }
        },
        methods: {
            //tab切换
            toggleTabs(i) {
                this.nowIndex = i;
            },
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        alert('submit!');
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
        },
    })
}